
import win32gui
import win32process
import psutil
def get_active_window_path():
    try:
        # 获取当前活动窗口的句柄
        hwnd = win32gui.GetForegroundWindow()
        _, pid = win32process.GetWindowThreadProcessId(hwnd)
        process = psutil.Process(pid)
        return process.exe()
    except Exception as e:
        print(f"获取窗口路径失败: {e}")
        return None
path = get_active_window_path()
if path:
    print(f"当前窗口程序路径: {path}")
else:
    print("无法获取当前窗口路径")